/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace ELE.Common.Util
{
  /// <summary>
  /// Utility class that provides functionality for formatting <see cref="DateTime"/> strings
  /// </summary>
  public class DateTimeFormatManager
  {
    /// <summary>
    /// 
    /// </summary>
    static public DateTimeFormatDictionary manager = new DateTimeFormatDictionary();
    /// <summary>
    /// 
    /// </summary>
    public class DateTimeFormatDictionary : Hashtable
    {
      /// <summary>
      /// 
      /// </summary>
      /// <param name="format"></param>
      /// <param name="newPattern"></param>
      public void SetDateFormatPattern(DateTimeFormatInfo format, String newPattern)
      {
        if (this[format] != null)
          ((DateTimeFormatProperties)this[format]).DateFormatPattern = newPattern;
        else
        {
          DateTimeFormatProperties tempProps = new DateTimeFormatProperties();
          tempProps.DateFormatPattern = newPattern;
          Add(format, tempProps);
        }
      }
      /// <summary>
      /// 
      /// </summary>
      /// <param name="format"></param>
      /// <returns></returns>
      public string GetDateFormatPattern(DateTimeFormatInfo format)
      {
        if (this[format] == null)
          return "d-MMM-yy";
        else
          return ((DateTimeFormatProperties)this[format]).DateFormatPattern;
      }
      /// <summary>
      /// 
      /// </summary>
      /// <param name="format"></param>
      /// <param name="newPattern"></param>
      public void SetTimeFormatPattern(DateTimeFormatInfo format, String newPattern)
      {
        if (this[format] != null)
          ((DateTimeFormatProperties)this[format]).TimeFormatPattern = newPattern;
        else
        {
          DateTimeFormatProperties tempProps = new DateTimeFormatProperties();
          tempProps.TimeFormatPattern = newPattern;
          Add(format, tempProps);
        }
      }
      /// <summary>
      /// 
      /// </summary>
      /// <param name="format"></param>
      /// <returns></returns>
      public string GetTimeFormatPattern(DateTimeFormatInfo format)
      {
        if (this[format] == null)
          return "h:mm:ss tt";
        else
          return ((DateTimeFormatProperties)this[format]).TimeFormatPattern;
      }
      /// <summary>
      /// 
      /// </summary>
      class DateTimeFormatProperties
      {
        public string DateFormatPattern = "d-MMM-yy";
        public string TimeFormatPattern = "h:mm:ss tt";
      }
    }
  }
}
